<?php

// @formatter:off
/**
 * @file AutoTaggerCron.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: AutoTaggerCron.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/extensions/AutoTagger/includes/AutoTaggerCron.php $
 */
// @formatter:on

include WC_E_AUTOTAGGER_ROOTDIR."/includes/AutoTagger.php";

class AutoTaggerCron extends WCCronTool {
	//
	// Public methods.
	public function run($spacer = "") {
		global $wcOptions;

		$groupId = $wcOptions->activated("Group") ? $wcOptions->value("Group") : false;
		$verbose = $wcOptions->activated("Verbose");

		foreach(WCGroupsHolder::I()->items() as $group) {
			//
			// Ignoring not matching groups when there's a specified
			// one.
			if($groupId && $group->id != $groupId) {
				continue;
			}
			if(is_readable($group->root)) {
				AutoTagger::I()->runCron($group, $spacer, $verbose );
			}
		}
	}
	public function showHelp($spacer = "") {
		//echo "{$spacer}This tool adds tag '{self::$TagNoName}' to any comics without
		// tags.\n\n";
		echo "{$spacer}Options:\n";
		echo "{$spacer}\t-g group-id, --group group-id\n";
		echo "{$spacer}\t\tIt only for a specific group.\n\n";
		echo "{$spacer}\t-v, --verbose\n";
		echo "{$spacer}\t\tShows more information.\n\n";
	}
	//
	// Protected methods.
	protected function loadOptions() {
		if(!$this->_optionsLoaded) {
			global $wcOptions;

			if($wcOptions->addValueOption("Group")) {
				$wcOptions->addOptionTrigger("Group", "g");
				$wcOptions->addOptionTrigger("Group", "group");
			}
			if($wcOptions->addOption("Verbose")) {
				$wcOptions->addOptionTrigger("Verbose", "v");
				$wcOptions->addOptionTrigger("Verbose", "verbose");
			}

			$wcOptions->check();

			$this->_optionsLoaded = true;
		}
	}
}
